// ListDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DriftWindow.h"
#include "ListDlg.h"
#include "DriftWindowDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CListDlg dialog


CListDlg::CListDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CListDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CListDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CListDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CListDlg)
	DDX_Control(pDX, IDC_LIST_POP, m_listSelect);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CListDlg, CDialog)
	//{{AFX_MSG_MAP(CListDlg)
	ON_WM_SIZE()
	ON_LBN_SELCHANGE(IDC_LIST_POP, OnSelchangeListPop)
	ON_LBN_DBLCLK(IDC_LIST_POP, OnDblclkListPop)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CListDlg message handlers


void CListDlg::EnChangeEditKeyfairyInput(CString strKey, HWND hWnd, HWND hWndEdit)
{
	m_hWnd = hWnd;
	m_hWndEdit = hWndEdit;

	for (int i=0; i<m_listSelect.GetCount(); i++)
	{
		CString strFuturesCode;
		m_listSelect.GetText(i, strFuturesCode);
		if (strFuturesCode.Find(strKey) >= 0)
		{
			break;
		}
	}
	
}

void CListDlg::OnDblclkListPop() 
{
	// TODO: Add your control notification handler code here
	int nSel=m_listSelect.GetCurSel();

	if(nSel>=0)
	{
		CString str;
		m_listSelect.GetText(nSel,str);
		if (::IsWindow(m_hWnd) && (GetSafeHwnd() != m_hWnd))
		{
			const char* pBuf = (const char*)str;
			::SendMessage(m_hWnd, MSG_CODE_KEY, (WPARAM)this, (LPARAM)pBuf);
		}
	}
}

void CListDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	if (m_listSelect.GetSafeHwnd())
	{
		m_listSelect.MoveWindow(1, 1, cx-2, cy-2);
	}
}

BOOL CListDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->wParam==VK_RETURN)
	{
		OnDblclkListPop();
	}
	if(pMsg->message == WM_MOUSEMOVE)
	{
		CPoint point;
		GetCursorPos(&point);
		ScreenToClient(&point);
		BOOL bOutside;
		UINT uItem = m_listSelect.ItemFromPoint(point,bOutside);
		
	//	if(!bOutside)
	//	{
			m_listSelect.SetCurSel(uItem);
	//	}
	}
	return CDialog::PreTranslateMessage(pMsg);
}

void CListDlg::OnSelchangeListPop()
{
	// TODO: Add your control notification handler code here
	OnDblclkListPop();
}

void CListDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CRect rc;
	GetClientRect(&rc);

	CPen penList(PS_SOLID,1,RGB(192,192,192));
	CPen *pOldPenEdit=dc.SelectObject(&penList);
	
	dc.FillRect(&rc,new CBrush(RGB(255,0,0)));
	//	rc_edit.bottom -= 1;
	dc.Rectangle(&rc);
	dc.SelectObject(pOldPenEdit);

	
	// Do not call CDialog::OnPaint() for painting messages
}
